#include <iostream>
#include <string>
#include <fstream>
#include "boost/date_time/posix_time/posix_time.hpp"

// with -lboost_date_time

int main()
{
	/*std::string ts1("2011-04-12 18:32:32.318773");
	boost::posix_time::ptime t1(boost::posix_time::time_from_string(ts1));
	std::string ts2("2011-04-12 18:32:37.006854");
	boost::posix_time::ptime t2(boost::posix_time::time_from_string(ts2));	
	
	boost::posix_time::time_duration t3 = t2 - t1;
	std::string result = boost::posix_time::to_simple_string(t3);
	std::cout << result << std::endl;*/
	
	boost::posix_time::time_duration tSum = boost::posix_time::microseconds(0);
	
	std::ifstream res("result.txt");
	std::string s1;
	std::string s2;
	boost::posix_time::ptime first;
	boost::posix_time::ptime last;
	int tic = 0;
	
	while(getline(res, s1))
	{
		++tic;
		if (getline(res, s2))
		{
			++tic;			
			boost::posix_time::ptime t1(boost::posix_time::time_from_string(s1));
			boost::posix_time::ptime t2(boost::posix_time::time_from_string(s2));
			boost::posix_time::time_duration t3 = t2 - t1;
			
			if (tic == 2)
				first = t1;
			if (tic == 58)
				last = t2;
			
			tSum += t3;			
		}
	 }
	
	std::cout << tSum << std::endl;	
	
	boost::posix_time::time_duration allTime = last - first;
	std::cout << allTime << std::endl;	
	
	long double q = (long double)tSum.total_microseconds() / allTime.total_microseconds();
	std::cout << q << std::endl;
	
	std::ofstream numRes("numbersResultN.txt", std::ios_base::app);
	numRes << q << std::endl;
	
	
}
